﻿
$(function () {
    var map = new GMaps({
        zoom: 9,
        div: '#map_canvas',
        lat: 43.744313,
        lng: -79.474119
    });

    $('#locationFilter a').click(function () {

        $('#locationFilter a').removeClass('label');
        $(this).addClass('label');

        var filter = $(this).data('filter');

        if (filter === "*") {
            $.each(map.markers, function (i, obj) {
                obj.setVisible(true);
            });
        }
        else {
            $.each(map.markers, function (i, obj) {
                obj.setVisible(obj.details.type === filter);
            });
        }
    });

    $.getJSON("/Location/GetAllJSON", null, function (data) {
        console.log(data);
        $.each(data, function (i, location) {
            var html = "<h5>" + location.Name + "</h5>";
            html += "<p>" + location.Address + "</p>";

            if (location.Phone !== "0") {
                html += "<a href='tel:" + location.Phone + "' class='secondary button'><i class='icon-phone'></i></a> ";
            }

            if (location.Email !== "0") {
                html += "<a href='mailto:" + location.Email + "' class='secondary button'><i class='icon-mail'></i></a> ";
            }

            html += "<a href='/Location/Details/" + location.ID + "' class='button'>View</a>";

            var image;

            if (location.LocationType == "Religious") {
                image = "/Images/religious.png";
            }
            else if (location.LocationType == "Hotel") {
                image = "/Images/hotel.png";
            }
            else if (location.LocationType == "Historical") {
                image = "/Images/historical.png";
            }
            else if (location.LocationType == "Country Club") {
                image = "/Images/golf.png";
            }
            else if (location.LocationType == "Hall") {
                image = "/Images/hall.png";
            }
            else {
                image = "/Images/all.png";
            }

            map.addMarker({
                title: location.Name,
                lat: location.Lat,
                lng: location.Lng,
                details: {
                    type: location.LocationType
                },
                infoWindow: {
                    content: html
                },
                icon: image
            });
        });
    });
});